package cn.epsilon3.autoConfigure;

import cn.epsilon3.configBean.InitializingTokenConfig;
import cn.epsilon3.service.jwtProcessor.JwtTokenProcessor;
import cn.epsilon3.service.jwtProcessor.impl.JwtTokenProcessorImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * token自动注入
 *
 * @author epsilon3
 */
@Configuration
@ConditionalOnClass(value = {JwtTokenProcessor.class, JwtTokenProcessorImpl.class})
@EnableConfigurationProperties(value = InitializingTokenConfig.class)
public class TokenServiceAutoConfigure {

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(
            name = {"epsilon3.config.token.buildWay"},
            havingValue = "jwt",
            matchIfMissing = true
    )
    public JwtTokenProcessor jwtTokenProcessor() {
        return new JwtTokenProcessorImpl();
    }
}
